{{#eq apps "link"}}
package {{packageName}}.api.{{apps}}.dict;

import cn.ibizlab.edge.api.link.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@Api(tags = {"数据字典" })
@RestController("link-DictHtmlResource")
@RequestMapping("/link/dict")
@ApiSupport(order = 99)
public class DictHtmlResource {


    @Autowired
    private DictService dictService;

    @RequestMapping(method = RequestMethod.GET, value = "/sync")
    public ResponseEntity<String> sync() {
        dictService.syncDict();
        return ResponseEntity.ok("同步完成");
    }

    private String html="<html lang=\"en\"><head><meta charset=\"UTF-8\"><title></title>" +
            "<style>table.reference,table.tecspec {table-layout:fixed;word-break:break-all;border-collapse: collapse;width:100%%;margin: 4px}  table.reference .fa {font-size: 24px;}  table.reference td:nth-child(odd) {background-color: #f2f7f9}  table.reference td:nth-child(even) {background-color: #fff}  table.reference tr.fixzebra {background-color: #f6f4f0}  table.reference th {line-height: 2em;min-width: 24px;color: #fff;background-color: #555;border: 1px solid #555;font-size: 12px;padding: 3px;vertical-align: top;text-align: left}  table.reference td {line-height: 2em;min-width: 24px;border: 1px solid #d4d4d4;padding: 5px;padding-top: 7px;padding-bottom: 7px;font-size: 12px;vertical-align: top;color: #606266;}  .captr{height:0px;border: 0px;margin:0px;padding:0px}" +
            "</style></header><body>%s<br/></body></html>";
    private String template="<table class=\"reference\" id=\"%s\"><tr><th colspan=\"3\" align=\"center\">%s</th></tr>" +
            "<tr><th>值</th><th>显示</th><th>上级值</th></tr>%s</table>";
    private String templateItem="<tr><td>%s</td><td>%s</td><td>%s</td></tr>";


    {{#each app.dicts}}
    @ApiOperation(value = "字典：{{name}}[{{pascalCase codeName}}Dict]", tags = {"数据字典" },  notes = "字典：{{name}}[{{pascalCase codeName}}Dict]")
    @RequestMapping(method = RequestMethod.GET, value = "/{{pascalCase codeName}}Dict.html")
    public ResponseEntity<String> show{{pascalCase codeName}}Dict() {
        List<String> tr=new ArrayList<>();
        new {{pascalCase codeName}}Dict().getAllItems().forEach(item->tr.add(String.format(templateItem,item.getValue(),item.getLabel(),item.getParent()==null?"":item.getParent())));
        return ResponseEntity.ok(String.format(html,String.format(template,"{{pascalCase codeName}}Dict","字典：{{name}}[{{pascalCase codeName}}Dict]",String.join("",tr))));
    }

    {{/each}}


}
{{/eq}}