/*
|
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
*
|
* Redistribution and use in source and binary forms, with or without
|
* modification, are permitted provided that the following conditions are met:
|
*
|
* Redistributions of source code must retain the above copyright notice,
|
* this list of conditions and the following disclaimer.
|
* Redistributions in binary form must reproduce the above copyright
|
* notice, this list of conditions and the following disclaimer in the
|
* documentation and/or other materials provided with the distribution.
|
* Neither the name of the dreamlu.net developer nor the names of its
|
* contributors may be used to endorse or promote products derived from
|
* this software without specific prior written permission.
|
* Author: Chill 庄骞 (smallchill@163.com)
|
*/
|
package org.springblade.modules.social.controller;
|
|
import com.alibaba.excel.EasyExcel;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiParam;
|
import lombok.AllArgsConstructor;
|
import org.apache.commons.codec.Charsets;
|
import org.springblade.common.excel.RowWriteHandler;
|
import org.springblade.core.boot.ctrl.BladeController;
|
import org.springblade.core.excel.util.ExcelUtil;
|
import org.springblade.core.mp.support.Condition;
|
import org.springblade.core.mp.support.Query;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.utils.DateUtil;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.modules.social.entity.Social;
|
import org.springblade.modules.social.excel.SocialExcel;
|
import org.springblade.modules.social.excel.SocialImporter;
|
import org.springblade.modules.social.service.ISocialService;
|
import org.springblade.modules.social.vo.SocialVO;
|
import org.springblade.modules.system.excel.UserExcel;
|
import org.springblade.modules.system.service.MyAsyncService;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import javax.validation.Valid;
|
import java.io.IOException;
|
import java.net.URLEncoder;
|
import java.text.ParseException;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* 控制器
|
*
|
* @author BladeX
|
* @since 2021-07-16
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/social")
|
@Api(value = "", tags = "接口")
|
public class SocialController extends BladeController {
|
|
private final ISocialService socialService;
|
|
private final MyAsyncService myAsyncService;
|
|
/**
|
* 详情
|
*/
|
@GetMapping("/detail")
|
@ApiOperationSupport(order = 1)
|
@ApiOperation(value = "详情", notes = "传入social")
|
public R<Social> detail(Social social) {
|
Social detail = socialService.getOne(Condition.getQueryWrapper(social));
|
return R.data(detail);
|
}
|
|
/**
|
* 分页
|
*/
|
@GetMapping("/list")
|
@ApiOperationSupport(order = 2)
|
@ApiOperation(value = "分页", notes = "传入social")
|
public R<IPage<Social>> list(Social social, Query query) {
|
IPage<Social> pages = socialService.page(Condition.getPage(query), Condition.getQueryWrapper(social));
|
return R.data(pages);
|
}
|
|
/**
|
* 自定义分页
|
*/
|
@GetMapping("/page")
|
@ApiOperationSupport(order = 3)
|
@ApiOperation(value = "分页", notes = "传入social")
|
public R<IPage<SocialVO>> page(SocialVO social, Query query) {
|
IPage<SocialVO> pages = socialService.selectSocialPage(Condition.getPage(query), social);
|
return R.data(pages);
|
}
|
|
/**
|
* 新增
|
*/
|
@PostMapping("/save")
|
@ApiOperationSupport(order = 4)
|
@ApiOperation(value = "新增", notes = "传入social")
|
public R save(@Valid @RequestBody Social social) {
|
//更新用户是否缴纳社保状态
|
socialService.upSoil(social.getCardid());
|
//新增社保缴纳记录
|
boolean save = socialService.save(social);
|
if (save){
|
String sql =
|
"insert into sys_socil(id,namb,sex,nation,telephone,cardid,residence,amount,insuredtime,deptid) " +
|
"values(" + "'" + social.getId() + "'"
|
+ "," + "'" + social.getNamb() + "'"
|
+ "," + "'" + social.getSex() + "'" +
|
"," + "'" + social.getNation() + "'" +
|
"," + "'" + social.getTelephone() + "'" +
|
"," + "'" + social.getCardid() + "'" +
|
"," + "'" + social.getResidence() + "'" +
|
"," + "'" + social.getAmount() + "'" +
|
"," + "'" + new SimpleDateFormat("yyyy-MM-dd").format(social.getInsuredtime()) + "'" +
|
"," + "'" + social.getDeptid() + "'" + ")";
|
myAsyncService.dataSync(sql);
|
}
|
//返回
|
return R.status(save);
|
}
|
|
/**
|
* 修改
|
*/
|
@PostMapping("/update")
|
@ApiOperationSupport(order = 5)
|
@ApiOperation(value = "修改", notes = "传入social")
|
public R update(@Valid @RequestBody Social social) {
|
return R.status(socialService.updateById(social));
|
}
|
|
/**
|
* 新增或修改
|
*/
|
@PostMapping("/submit")
|
@ApiOperationSupport(order = 6)
|
@ApiOperation(value = "新增或修改", notes = "传入social")
|
public R submit(@Valid @RequestBody Social social) {
|
return R.status(socialService.saveOrUpdate(social));
|
}
|
|
|
/**
|
* 删除
|
*/
|
@PostMapping("/remove")
|
@ApiOperationSupport(order = 8)
|
@ApiOperation(value = "删除", notes = "传入ids")
|
@Transactional(rollbackFor = Exception.class)
|
public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
|
boolean remove = socialService.removeByIds(Func.toLongList(ids));
|
if (remove) {
|
List<String> list = Arrays.asList(ids.split(","));
|
list.forEach(s -> {
|
//内网同步删除
|
String s1 = "delete from sys_socil where id = " + "'" + s + "'";
|
myAsyncService.dataSync(s1);
|
});
|
}
|
return R.status(remove);
|
}
|
|
|
/**
|
* 导入社保
|
*/
|
@PostMapping("import-user")
|
@ApiOperationSupport(order = 12)
|
public R importUser(MultipartFile file,String deptid) {
|
SocialImporter socialImporter = new SocialImporter(socialService, false,deptid);
|
ExcelUtil.save(file, socialImporter, SocialExcel.class);
|
return R.success("操作成功");
|
}
|
|
/**
|
* 导出模板
|
*/
|
@GetMapping("export-template")
|
@ApiOperationSupport(order = 14)
|
@ApiOperation(value = "导出模板")
|
public void exportUser(HttpServletResponse response) throws IOException, ParseException {
|
List<SocialExcel> list = new ArrayList<>();
|
SocialExcel socialExcel = new SocialExcel();
|
socialExcel.setNamb("张三");
|
socialExcel.setSex("男");
|
socialExcel.setNation("汉");
|
socialExcel.setBirthday(new SimpleDateFormat("yyyy/MM/dd").parse("1999/5/1"));
|
socialExcel.setTelephone("13112341234");
|
socialExcel.setCardid("360XXX19XXXXXX****");
|
socialExcel.setResidence("江西省南昌市***********");
|
socialExcel.setAddress("江西省南昌市***********");
|
socialExcel.setNature("城镇");
|
socialExcel.setAmount("1000.00");
|
socialExcel.setInsuredtime(new SimpleDateFormat("yyyy/MM/dd").parse("2020/5/1"));
|
list.add(socialExcel);
|
|
SocialExcel socialExcel1 = new SocialExcel();
|
socialExcel1.setNamb("李四");
|
socialExcel1.setSex("女");
|
socialExcel1.setNation("汉");
|
socialExcel1.setBirthday(new SimpleDateFormat("yyyy/MM/dd").parse("1999/5/1"));
|
socialExcel1.setTelephone("13112341234");
|
socialExcel1.setCardid("360XXX19XXXXXX****");
|
socialExcel1.setResidence("江西省南昌市***********");
|
socialExcel1.setAddress("江西省南昌市***********");
|
socialExcel1.setNature("农村");
|
socialExcel1.setAmount("1000.00");
|
socialExcel1.setInsuredtime(new SimpleDateFormat("yyyy/MM/dd").parse("2020/5/1"));
|
list.add(socialExcel1);
|
String fileName = null;
|
try {
|
response.setContentType("application/vnd.ms-excel");
|
response.setCharacterEncoding(org.apache.commons.codec.Charsets.UTF_8.name());
|
fileName = URLEncoder.encode("社保数据模板"+ DateUtil.time(), Charsets.UTF_8.name());
|
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
|
//修改单元格格式为文本格式
|
EasyExcel.write(response.getOutputStream(), SocialExcel.class).sheet("社保数据模板").registerWriteHandler(new RowWriteHandler()).doWrite(list);
|
} catch (Throwable var6) {
|
throw var6;
|
}
|
// ExcelUtil.export(response, "社保数据模板", "社保数据模板", list, SocialExcel.class);
|
}
|
}
|